<script>
  function test() {
    console.log(this);
  }

  //   test.apply(111, [1, 2, 3]);

  Function.prototype.myApply = function (ctx, args) {
    if (!Array.isArray(args))
      throw new Error('CreateListFromArrayLike called on non-object');
    ctx = [undefined, null].includes(ctx) ? globalThis : Object(ctx);
    const key = Symbol();
    Object.defineProperty(ctx, key, {
      configurable: true,
      enumerable: false,
      value: this,
    });
    let result = ctx[key](...args);
    delete ctx[key];
    return result;
  };

  test.myApply({}, [1, 2, 3]);
</script>
